﻿// ----------------------------------------------------------------
// Description : 实体类,该文件由MyGeneration生成
// Author      : 
// Create date : 2010-1-12
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ITOMMS.Entity
{
	/// <summary>
	///	tb工作计划总结表 Entity
	///	tb工作计划总结表 Entity工作计划总结表
	/// </summary>
	[Serializable]
	public class tb工作计划总结表Entity : BaseEntity<tb工作计划总结表Entity,int>
	{
		
		#region 私有成员			
		
		private int _ID; 
		private int? _用户ID; 
		private string _姓名; 
		private int? _部门; 
		private string _职位; 
		private DateTime? _日期; 
		private DateTime? _计划时间起; 
		private DateTime? _计划时间止; 
		private string _第几周; 
		private string _工作计划内容; 
		private string _工作计划总结; 
		private DateTime? _CreateDate; 
		private int? _CreateBy; 
		private DateTime? _ModifyDate; 
		private int? _ModifyBy; 
		private int _SEQNO;
		#endregion


		
		#region 默认( 空 ) 构造函数
		/// <summary>
		/// 默认构造函数
		/// </summary>
		public tb工作计划总结表Entity()
		{
			_ID = 0; 
			_用户ID =  null; 
			_姓名 = String.Empty; 
			_部门 =  null; 
			_职位 = String.Empty; 
			_日期 =  null; 
			_计划时间起 =  null; 
			_计划时间止 =  null; 
			_第几周 = String.Empty; 
			_工作计划内容 = String.Empty; 
			_工作计划总结 = String.Empty; 
			_CreateDate =  null; 
			_CreateBy =  null; 
			_ModifyDate =  null; 
			_ModifyBy =  null; 
			_SEQNO = 0;
		}
		#endregion
		
		#region 属性值校验
		
		/// <summary>
		/// 属性值校验
		/// </summary>
		public bool CheckValues()
		{
			bool bResult = true;
			string strError = "";
		
			if ( _ID ==  0)
			{
				bResult = false;
				strError += "\r\n 非空值不能为: "+_ID;
			}
			
			if( !bResult )
					throw new ArgumentOutOfRangeException(strError);
			return bResult;
			
		}
		
		#endregion
		
		
		
	
		#region Required Fields Only Constructor
		
		/// <summary>
		/// required (not null) fields only constructor
		/// </summary>
		public tb工作计划总结表Entity(
		int para_ID		)
		: this()
		{
					_ID = para_ID;
			_用户ID = null;
			_姓名 = String.Empty;
			_部门 = null;
			_职位 = String.Empty;
			_日期 = null;
			_计划时间起 = null;
			_计划时间止 = null;
			_第几周 = String.Empty;
			_工作计划内容 = String.Empty;
			_工作计划总结 = String.Empty;
			_CreateDate = null;
			_CreateBy = null;
			_ModifyDate = null;
			_ModifyBy = null;
		}
		#endregion 

		
		#region 公有属性
			
			/// <summary>
			/// 行号，顺序号。系统默认的属性,对这个属性不要作操作.属性值在架构中已经处理
			/// </summary>
			public virtual int SEQNO
			{
				get { return _SEQNO; }
				set { _SEQNO = value; }
			}
		
			
		/// <summary>
		/// IDID
		/// </summary>		
		public virtual int ID
		{
			get { return _ID; }
			set { _ID = value; }
		}
			
		/// <summary>
		/// 用户ID用户ID
		/// </summary>		
		public virtual int? 用户ID
		{
			get { return _用户ID; }
			set { _用户ID = value; }
		}
			
		/// <summary>
		/// 姓名姓名
		/// </summary>		
		public virtual string 姓名
		{
			get { return _姓名; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 50)
						throw new ArgumentOutOfRangeException("Invalid value for 姓名", value, value.ToString());
				
				_姓名 = value;
			}
		}
			
		/// <summary>
		/// 部门部门
		/// </summary>		
		public virtual int? 部门
		{
			get { return _部门; }
			set { _部门 = value; }
		}
			
		/// <summary>
		/// 职位职位
		/// </summary>		
		public virtual string 职位
		{
			get { return _职位; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 50)
						throw new ArgumentOutOfRangeException("Invalid value for 职位", value, value.ToString());
				
				_职位 = value;
			}
		}
			
		/// <summary>
		/// 日期日期
		/// </summary>		
		public virtual DateTime? 日期
		{
			get { return _日期; }
			set { _日期 = value; }
		}
			
		/// <summary>
		/// 计划时间起计划时间起
		/// </summary>		
		public virtual DateTime? 计划时间起
		{
			get { return _计划时间起; }
			set { _计划时间起 = value; }
		}
			
		/// <summary>
		/// 计划时间止计划时间止
		/// </summary>		
		public virtual DateTime? 计划时间止
		{
			get { return _计划时间止; }
			set { _计划时间止 = value; }
		}
			
		/// <summary>
		/// 第几周第几周
		/// </summary>		
		public virtual string 第几周
		{
			get { return _第几周; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 10)
						throw new ArgumentOutOfRangeException("Invalid value for 第几周", value, value.ToString());
				
				_第几周 = value;
			}
		}
			
		/// <summary>
		/// 工作计划内容工作计划内容
		/// </summary>		
		public virtual string 工作计划内容
		{
			get { return _工作计划内容; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 2147483647)
						throw new ArgumentOutOfRangeException("Invalid value for 工作计划内容", value, value.ToString());
				
				_工作计划内容 = value;
			}
		}
			
		/// <summary>
		/// 工作计划总结工作计划总结
		/// </summary>		
		public virtual string 工作计划总结
		{
			get { return _工作计划总结; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 2147483647)
						throw new ArgumentOutOfRangeException("Invalid value for 工作计划总结", value, value.ToString());
				
				_工作计划总结 = value;
			}
		}
			
		/// <summary>
		/// CreateDate创建时间
		/// </summary>		
		public virtual DateTime? CreateDate
		{
			get { return _CreateDate; }
			set { _CreateDate = value; }
		}
			
		/// <summary>
		/// CreateBy创建人
		/// </summary>		
		public virtual int? CreateBy
		{
			get { return _CreateBy; }
			set { _CreateBy = value; }
		}
			
		/// <summary>
		/// ModifyDate修改时间
		/// </summary>		
		public virtual DateTime? ModifyDate
		{
			get { return _ModifyDate; }
			set { _ModifyDate = value; }
		}
			
		/// <summary>
		/// ModifyBy修改人
		/// </summary>		
		public virtual int? ModifyBy
		{
			get { return _ModifyBy; }
			set { _ModifyBy = value; }
		}
			


		#endregion 	
		
		
        #region DAO操作
		
		
		/// <summary>
        /// 获取所有实体的列表
        /// </summary>
        /// <returns></returns>
        public override List<tb工作计划总结表Entity> GetAll()
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_工作计划总结表] ");
	
            List<tb工作计划总结表Entity> list = new List<tb工作计划总结表Entity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq = 0;
                while (dataReader.Read())
                {	seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		/// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords()
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("  select count([ID])  from [tb_工作计划总结表] ");
	
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }
		
		/// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords(string sqlCondition)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("  select count([ID])  from [tb_工作计划总结表]  ");
	
			 if (sqlCondition.Trim() != "")
            {
                strSql.Append(" where " + sqlCondition);
            }
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }	
		
		
		/// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
		/// <param name="PageSize">每页大小</param>
		/// <param name="CurrentPageIndex">当前页码</param>
        /// <returns></returns>
		 public override List<tb工作计划总结表Entity> GetAllByQuery(string strWhere, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }
		 
			strSql.Append("select top ").Append(PageSize).Append("  [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_工作计划总结表] where ");

			 if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
			  strSql.Append(" ID not in ( ");
			 strSql.Append(" select top ").Append(PageSize*(CurrentPageIndex-1)).Append("  [ID] from [tb_工作计划总结表] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere );
            }
			strSql.Append(" ) " );

            List<tb工作计划总结表Entity> list = new List<tb工作计划总结表Entity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
			   int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }
		
		
			/// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
		/// <param name="PageSize">每页大小</param>
		/// <param name="CurrentPageIndex">当前页码</param>
		/// <param name="strSort">ex:order by id desc</param>
        /// <returns></returns>
		 public override List<tb工作计划总结表Entity> GetAllByQuery(string strWhere,string strSort, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }
		 
			strSql.Append("select top ").Append(PageSize).Append("  [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_工作计划总结表] where ");

			 if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
			  strSql.Append(" ID not in ( ");
			 strSql.Append(" select top ").Append(PageSize*(CurrentPageIndex-1)).Append("  [ID] from [tb_工作计划总结表] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere+" " ).Append(strSort);
            }
			strSql.Append(" ) " ).Append(strSort);

            List<tb工作计划总结表Entity> list = new List<tb工作计划总结表Entity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {	
					seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }
		
		
		/// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public override List<tb工作计划总结表Entity> GetAllByQuery(string strWhere)
        {
			strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from tb_工作计划总结表 ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tb工作计划总结表Entity> list = new List<tb工作计划总结表Entity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            { 
				int seq = 0;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		
		/// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
		/// <param name="parameters">sql条件中的参数</param>
        /// <returns></returns>
        public override List<tb工作计划总结表Entity> GetAllByQuery(string strWhere, List<IDataParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_工作计划总结表] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tb工作计划总结表Entity> list = new List<tb工作计划总结表Entity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
				int seq =0 ;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		

		
		
		/// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tb工作计划总结表Entity> GetAllByQuery(string strWhere, List<IDataParameter> parameters, int rowNumber)
        {

            StringBuilder strSql = new StringBuilder();
			strSql.Append("select top ").Append(rowNumber).Append("  [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_工作计划总结表] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tb工作计划总结表Entity> list = new List<tb工作计划总结表Entity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {	
				int seq = 0;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		/// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句: AND AA=@AA</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tb工作计划总结表Entity> GetAllByQuery(string strWhere, int rowNumber)
        {
		    strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
			
			strSql.Append("select top ").Append(rowNumber).Append("  [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_工作计划总结表] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where  " + strWhere);
            }
            List<tb工作计划总结表Entity> list = new List<tb工作计划总结表Entity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq=0;
                while (dataReader.Read())
                {	
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		
		
		
		
		
        /// <summary>
        /// 按主键查询对应的实体
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public override tb工作计划总结表Entity GetById(int id)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_工作计划总结表]  where ID= @ID ");
				
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            tb工作计划总结表Entity entity = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    entity = ReaderBind(dataReader);
                }
            }
            return entity;

        }
		
		
		 /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save()
        {
			
            if (this.ID ==0)
            {
                this.ID = GetMax("tb_工作计划总结表");
            }
            StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into  tb_工作计划总结表 (");
			strSql.Append("[ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] )");
			strSql.Append(" values (");
			strSql.Append("@ID,@用户ID,@姓名,@部门,@职位,@日期,@计划时间起,@计划时间止,@第几周,@工作计划内容,@工作计划总结,@CreateDate,@CreateBy,@ModifyDate,@ModifyBy)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID);
			if (this.用户ID == null)
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, this.用户ID.Value);
			}
			db.AddInParameter(dbCommand, "姓名", DbType.String, this.姓名);
			if (this.部门 == null)
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, this.部门.Value);
			}
			db.AddInParameter(dbCommand, "职位", DbType.String, this.职位);
			if (this.日期 == null)
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, this.日期.Value);
			}
			if (this.计划时间起 == null)
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, this.计划时间起.Value);
			}
			if (this.计划时间止 == null)
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, this.计划时间止.Value);
			}
			db.AddInParameter(dbCommand, "第几周", DbType.String, this.第几周);
			db.AddInParameter(dbCommand, "工作计划内容", DbType.String, this.工作计划内容);
			db.AddInParameter(dbCommand, "工作计划总结", DbType.String, this.工作计划总结);
			if (this.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
			}
			if (this.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
			}
			if (this.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
			}
			if (this.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
			}

			return db.ExecuteNonQuery(dbCommand);
		  
      
        }
		

		
        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save(tb工作计划总结表Entity entity)
        {
			
            if (entity.ID == 0)
            {
                entity.ID = GetMax("tb_工作计划总结表");
            }
            StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into  tb_工作计划总结表 (");
			strSql.Append("[ID],[用户ID],[姓名],[部门],[职位],[日期],[计划时间起],[计划时间止],[第几周],[工作计划内容],[工作计划总结],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] )");
			strSql.Append(" values (");
			strSql.Append("@ID,@用户ID,@姓名,@部门,@职位,@日期,@计划时间起,@计划时间止,@第几周,@工作计划内容,@工作计划总结,@CreateDate,@CreateBy,@ModifyDate,@ModifyBy)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
			if (entity.用户ID == null)
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, entity.用户ID.Value);
			}
			db.AddInParameter(dbCommand, "姓名", DbType.String, entity.姓名);
			if (entity.部门 == null)
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, entity.部门.Value);
			}
			db.AddInParameter(dbCommand, "职位", DbType.String, entity.职位);
			if (entity.日期 == null)
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, entity.日期.Value);
			}
			if (entity.计划时间起 == null)
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, entity.计划时间起.Value);
			}
			if (entity.计划时间止 == null)
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, entity.计划时间止.Value);
			}
			db.AddInParameter(dbCommand, "第几周", DbType.String, entity.第几周);
			db.AddInParameter(dbCommand, "工作计划内容", DbType.String, entity.工作计划内容);
			db.AddInParameter(dbCommand, "工作计划总结", DbType.String, entity.工作计划总结);
			if (entity.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
			}
			if (entity.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
			}
			if (entity.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
			}
			if (entity.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
			}

			return db.ExecuteNonQuery(dbCommand);
		  
      
        }
		
		
        /// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate(tb工作计划总结表Entity entity)
        {
			
            if (entity.ID  == 0)
            {
                if (Save(entity)>0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update(entity);
            }
        }
		
		/// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate()
        {
		
            if (this.ID  == 0)
            {
                if (Save()>0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update();
            }
        }
		
		/// <summary>
        /// 是否存在对应主键ID的记录
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override bool IsExist(int ID)
        {
            Database db = GetDatabase();
            StringBuilder strSql = new StringBuilder();
            			 strSql.Append("select count(1) from tb_工作计划总结表 where ID=@ID ");

            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, ID);//这里为ID是因为原有代码把主键都变成了ID.
            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
		
		
		/// <summary>
        /// 删除对应的实体
        /// </summary>
        /// <param name="entity"></param>
        public override int Delete(tb工作计划总结表Entity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_工作计划总结表 ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID );
            return db.ExecuteNonQuery(dbCommand);
        }
		
		/// <summary>
        /// 删除主键ID对应的记录
        /// </summary>
        /// <param name="id"></param>
        public override int Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_工作计划总结表 ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            return db.ExecuteNonQuery(dbCommand);
        }
		
		
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public override int Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tb_工作计划总结表 set ");
			strSql.Append("[ID]=@ID,[用户ID]=@用户ID,[姓名]=@姓名,[部门]=@部门,[职位]=@职位,[日期]=@日期,[计划时间起]=@计划时间起,[计划时间止]=@计划时间止,[第几周]=@第几周,[工作计划内容]=@工作计划内容,[工作计划总结]=@工作计划总结,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[ModifyBy]=@ModifyBy ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID );
			if (this.用户ID == null)
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, this.用户ID.Value);
			}
			db.AddInParameter(dbCommand, "姓名", DbType.String, this.姓名);
			if (this.部门 == null)
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, this.部门.Value);
			}
			db.AddInParameter(dbCommand, "职位", DbType.String, this.职位);
			if (this.日期 == null)
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, this.日期.Value);
			}
			if (this.计划时间起 == null)
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, this.计划时间起.Value);
			}
			if (this.计划时间止 == null)
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, this.计划时间止.Value);
			}
			db.AddInParameter(dbCommand, "第几周", DbType.String, this.第几周);
			db.AddInParameter(dbCommand, "工作计划内容", DbType.String, this.工作计划内容);
			db.AddInParameter(dbCommand, "工作计划总结", DbType.String, this.工作计划总结);
			if (this.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
			}
			if (this.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
			}
			if (this.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
			}
			if (this.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
			}

			
			return	db.ExecuteNonQuery(dbCommand);

		}
		



		
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public override int Update(tb工作计划总结表Entity entity)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tb_工作计划总结表 set ");
			strSql.Append("[ID]=@ID,[用户ID]=@用户ID,[姓名]=@姓名,[部门]=@部门,[职位]=@职位,[日期]=@日期,[计划时间起]=@计划时间起,[计划时间止]=@计划时间止,[第几周]=@第几周,[工作计划内容]=@工作计划内容,[工作计划总结]=@工作计划总结,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[ModifyBy]=@ModifyBy ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID );
			if (entity.用户ID == null)
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "用户ID", DbType.Int32, entity.用户ID.Value);
			}
			db.AddInParameter(dbCommand, "姓名", DbType.String, entity.姓名);
			if (entity.部门 == null)
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "部门", DbType.Int32, entity.部门.Value);
			}
			db.AddInParameter(dbCommand, "职位", DbType.String, entity.职位);
			if (entity.日期 == null)
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "日期", DbType.DateTime, entity.日期.Value);
			}
			if (entity.计划时间起 == null)
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间起", DbType.DateTime, entity.计划时间起.Value);
			}
			if (entity.计划时间止 == null)
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "计划时间止", DbType.DateTime, entity.计划时间止.Value);
			}
			db.AddInParameter(dbCommand, "第几周", DbType.String, entity.第几周);
			db.AddInParameter(dbCommand, "工作计划内容", DbType.String, entity.工作计划内容);
			db.AddInParameter(dbCommand, "工作计划总结", DbType.String, entity.工作计划总结);
			if (entity.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
			}
			if (entity.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
			}
			if (entity.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
			}
			if (entity.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
			}

			
			return	db.ExecuteNonQuery(dbCommand);

		}
		


		
		
		
		
		/// <summary>
        /// 对象实体绑定数据
		///生成构造为list的构造器
        /// </summary>
        private tb工作计划总结表Entity ReaderBind(IDataReader dataReader,int seq)
        {
            ITOMMS.Entity.tb工作计划总结表Entity entity = new ITOMMS.Entity.tb工作计划总结表Entity();
			entity.SEQNO = seq;
            object obj;
			obj = dataReader["ID"];
			 if (obj != null && obj != DBNull.Value)
			 {
			 entity.ID = (int)obj;
			 }
			 obj=dataReader["用户ID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.用户ID= (int)obj;
			}
			 entity.姓名= dataReader["姓名"].ToString();
			 obj=dataReader["部门"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.部门= (int)obj;
			}
			 entity.职位= dataReader["职位"].ToString();
			 obj=dataReader["日期"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.日期= (DateTime)obj;
			}
			 obj=dataReader["计划时间起"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.计划时间起= (DateTime)obj;
			}
			 obj=dataReader["计划时间止"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.计划时间止= (DateTime)obj;
			}
			 entity.第几周= dataReader["第几周"].ToString();
			 entity.工作计划内容= dataReader["工作计划内容"].ToString();
			 entity.工作计划总结= dataReader["工作计划总结"].ToString();
			 obj=dataReader["CreateDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateDate= (DateTime)obj;
			}
			 obj=dataReader["CreateBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateBy= (int)obj;
			}
			 obj=dataReader["ModifyDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyDate= (DateTime)obj;
			}
			 obj=dataReader["ModifyBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyBy= (int)obj;
			}

            return entity;
        }
		
		
				/// <summary>
        /// 对象实体绑定数据
		///生成构造为list的构造器
        /// </summary>
        private tb工作计划总结表Entity ReaderBind(IDataReader dataReader)
        {
            ITOMMS.Entity.tb工作计划总结表Entity entity = new ITOMMS.Entity.tb工作计划总结表Entity();
			object obj;
			obj = dataReader["ID"];
			 if (obj != null && obj != DBNull.Value)
			 {
			 entity.ID = (int)obj;
			 }
			 obj=dataReader["用户ID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.用户ID= (int)obj;
			}
			 entity.姓名= dataReader["姓名"].ToString();
			 obj=dataReader["部门"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.部门= (int)obj;
			}
			 entity.职位= dataReader["职位"].ToString();
			 obj=dataReader["日期"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.日期= (DateTime)obj;
			}
			 obj=dataReader["计划时间起"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.计划时间起= (DateTime)obj;
			}
			 obj=dataReader["计划时间止"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.计划时间止= (DateTime)obj;
			}
			 entity.第几周= dataReader["第几周"].ToString();
			 entity.工作计划内容= dataReader["工作计划内容"].ToString();
			 entity.工作计划总结= dataReader["工作计划总结"].ToString();
			 obj=dataReader["CreateDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateDate= (DateTime)obj;
			}
			 obj=dataReader["CreateBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateBy= (int)obj;
			}
			 obj=dataReader["ModifyDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyDate= (DateTime)obj;
			}
			 obj=dataReader["ModifyBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyBy= (int)obj;
			}

            return entity;
        }
		
		
		
		 #endregion
		
	}
}
